<%-- 
  -- Body List para Subject.
  --
  -- @author ariel.piechotka
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/displaytag-el.tld" prefix="display" %>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%-- Librerias para EXT library --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/xtheme-default.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    function modifySubject(subjectId) {
        var hiddenSubjectId = $("modifyIdId");
        hiddenSubjectId.value = subjectId;        
        var form = $("modifySubjectFormId");
        form.submit();
    } 

    function preDeleteSubject(subjectId) {
        var localHiddenIdObj = $("subjectToDeleteId");
        localHiddenIdObj.value = subjectId;

        Ext.MessageBox.confirm('Confirm', '&iquest;Est&aacute; seguro que desea eliminar la materia ' + name + ' ?', postDeleteSubject);
    }
    
    function listAcademicRecords(subjectId) {
        var hiddenSubjectId = $("subjectWithRecordsId");
        hiddenSubjectId.value = subjectId;        
        var form = $("listAcademicRecordsFormId");
        form.submit();
    }
    
   /** Post invocacion de la eliminacion de subject. */
    var postDeleteSubject = function(btn)  {
        var localHiddenIdObj = $("subjectToDeleteId");
        if (btn == "yes") {
            // Se quiere eliminar efectivamente
            var deleteHiddenObj = $("deleteSubjectId");
            deleteHiddenObj.value = localHiddenIdObj.value;
            
            var form = $("deleteSubjectFormId");
            form.submit();
        }
        else {
            localHiddenIdObj.value = "";
        }
    }
</script>


<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/listSubjects.do" styleId="subjectFormId">
    <%-- Inyectados por Javascript --%>
    <html:hidden name="subjectForm" property="id" styleId="subjectToDeleteId" value=""/>
    <%-- No pertenece al form de Struts. Se carga cada vez q se selecciona una materia a eliminar --%>
<%-- !    <input type="hidden" id="subjectToDeleteId" value="" > --%>
    
    <h2>Materias</h2>

    <bean:define id="subjects" name="subjectForm" property="subjects" />
    <display:table name="pageScope.subjects" sort="list" export="true" pagesize="15" requestURI="/protected/listSubjects.do" id="row" class="displayTable">

        <display:column title="Eliminar" class="columnGifLink" media="html">
            <img src="<html:rewrite page='/protected/img/trashcan_full.png'/>" alt="" name="submitButton" onclick="preDeleteSubject('<bean:write name="row" property="id" />')" title="Elimina a la materia...">
        </display:column>

        <display:column title="Modificar" class="columnGifLink" media="html">
            <img src="<html:rewrite page='/protected/img/kedit.png'/>" alt="" name="submitB" onclick="modifySubject('<bean:write name="row" property="id" />')" title="Modifica los datos de la materia...">
        </display:column>

        <display:column title="Ver actas" class="columnGifLink" media="html">
            <img src="<html:rewrite page='/protected/img/user.png'/>" alt="" name="submitAcadRec" onclick="listAcademicRecords('<bean:write name="row" property="id" />')" title="Muestra las actas de la materia ...">
        </display:column>

        <display:column title="Codigo" property="code" sortable="true" />
        <display:column title="Nombre" property="name" sortable="true" />
        <display:column title="Creditos" property="credits" sortable="true" />
		<display:column media="csv excel pdf" title="Fecha de alta" property="validFrom" sortable="false" />
    </display:table>    

</html:form>

<%-- Inyectados por Javascript --%>
<div id="modifyDivId" class="hideClass">
    <html:form action="/protected/showSubject" styleId="modifySubjectFormId">
        <html:hidden property="id" value="" styleId="modifyIdId" />
    </html:form>
</div>

<%-- Inyectados por Javascript --%>
<div id="deleteDivId" class="hideClass">
    <html:form action="/protected/deleteSubject" styleId="deleteSubjectFormId">
        <html:hidden property="id" value="" styleId="deleteSubjectId" />
    </html:form>
</div>

<%-- Inyectados por Javascript --%>
<div id="deleteDivId" class="hideClass">
    <html:form action="/protected/listAcademicRecords" styleId="listAcademicRecordsFormId">
        <html:hidden property="subjectId" value="" styleId="subjectWithRecordsId" />
    </html:form>
</div>
